package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.AdminDao;

/**
 * Servlet implementation class userDeleteRoot
 */
@WebServlet("/userDeleteRoot")
public class userDeleteRoot extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public userDeleteRoot() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");//防止出现中文乱码
		
		// 获取注册信息
		String account =request.getParameter("D");
		

		
		boolean a = AdminDao.userDelete(account);
		//将往册信息存入数据库，再返回登录
		if(a==true){
		request.getSession().setAttribute("D1","用户注销成功");
		response.sendRedirect("/aaa/ausersRoot.jsp");
		}else {
		request.getSession().setAttribute("D1","注销失败 用户不存在或者还有未完成订单");
		response.sendRedirect("/aaa/ausersRoot.jsp");
		}
	}

}
